package com.aya.transaction;

import com.aya.transaction.mapper.BlogMapper;
import com.aya.transaction.service.BlogSimpleTransactionService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 事物异常回滚
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringTransaction.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SimpleTransaction {

    @Resource
    BlogSimpleTransactionService blogSimpleTransactionService;

    @Test
    public void testSuccess() {
        blogSimpleTransactionService.updateById("1", "transaction success");
    }

    @Test
    public void testFailure() {
        blogSimpleTransactionService.updateByIdWithException("1", "transaction failure");
    }
}
